package com.sasis.service.impl;

import java.util.Collection;
import java.util.Iterator;

import com.sasis.model.Function;
import com.sasis.model.Handle;
import com.sasis.model.Subject;

public class PermissionValidator {

	private Collection allowFunctions;
	
	private Collection allowHandles;
	
	public boolean isAllow(Subject subject) {
		if (subject == null || subject.getId() == null) {
			return false;
		}
		if (subject.isFunction()) {
			for (Iterator iterator = allowFunctions.iterator(); iterator.hasNext();) {
				Function function = (Function)iterator.next();
				if (subject.getId().equals(function.getId())) {
					return true;
				}
			}
		} else {
			for (Iterator iterator = allowHandles.iterator(); iterator.hasNext();) {
				Handle handle = (Handle)iterator.next();
				if (subject.getId().equals(handle.getId())) {
					return true;
				}
			}
		}
		return false;
	}

	public Collection getAllowFunctions() {
		return allowFunctions;
	}

	public void setAllowFunctions(Collection allowFunctions) {
		this.allowFunctions = allowFunctions;
	}

	public Collection getAllowHandles() {
		return allowHandles;
	}

	public void setAllowHandles(Collection allowHandles) {
		this.allowHandles = allowHandles;
	}

}
